import { invoke } from "@tauri-apps/api/core";
import { useEffect, useState, useRef } from "react";
import { useSelector } from "react-redux";
import Upload from "../Upload";
import ParamsModal from "../../components/ParamsModal";

export default function UploadPage() {
  const [files, setFiles] = useState([]);
  const [loading, setLoading] = useState(true);
  let user = useSelector((state) => state.user.user);
  const params_ref = useRef();
  const open = () => {
    console.log("invoking...");

    params_ref.current.open();
  };
  useEffect(() => {
    const init_func = async () => {
      let res = await invoke("get_object_list", {
        username: user.username,
        fileType: "csv",
      });
      console.log(res);
      setFiles(res);
      setLoading(false);
    };
    init_func();
  }, []);
  return (
    <>
      <Upload files={files} loading={loading} open_modal={open}></Upload>
      <ParamsModal ref={params_ref}></ParamsModal>
    </>
  );
}
